package hashMapProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;

public class HashMapProxy {
    public static Map<String,Object> getInstance(){
        HashMap<String,Object> map = new HashMap<>();
        Map<String,Object> mapProxy = (Map<String,Object>)Proxy.newProxyInstance(HashMap.class.getClassLoader(), HashMap.class.getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("开始调用方法" + method.getName());
                Object invoke = method.invoke(map,args);
                System.out.println(method.getName() + "方法调用结束");
                return invoke;
            }
        });

        return mapProxy;
    }
}
